var bcrypt = require('bcryptjs');
var moment = require('moment');

moment.locale('zh-cn'); //使用中文

//格式化时间
exports.formatDate = function (date, firendly) {
    date = moment(date);

    if (firendly) {
        return date.formNow();
    } else {
        return date.format('YYYY-MM-DD HH:mm');
    }
};

exports.validateId = function (str) {
    return (/^[a-zA-Z0-9\-_]+$/i).test(str);
};

exports.bhash = function (str, callback) {
    bcrypt.hash(str, 10, callback);
};

exports.bcompare = function(str, hash, callback) {
    bcrypt.compare(str, hash, callback);
};